package com.jwater.web.ui.tag.components;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.ClosingUIBean;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;

import com.opensymphony.xwork2.util.ValueStack;

@StrutsTag(name = "tabpage", tldTagClass = "com.jwater.web.ui.tags.TabPageTag", description = "tabpage", allowDynamicAttributes = true)
public class TabPage extends ClosingUIBean {

	public static final String TEMPLATE = "tabpage";
	public static final String TEMPLATE_CLOSE = "tabpage-close";
	public static final String COMPONENT_NAME = TabPage.class.getName();
	
	protected String selected;
	protected String navigatetype;
	protected String navigateurl;
	protected String allowtargetinblank;
	
	@StrutsTagAttribute(description="tab if selected ", type = "Boolean", defaultValue = "false")
	public void setSelected(String selected) {
		this.selected = selected;
	}

	@StrutsTagAttribute(description="tab navigate type.options:contain,iframe,ajax ", type="String")
	public void setNavigatetype(String navigatetype) {
		this.navigatetype = navigatetype;
	}

	@StrutsTagAttribute(description="tab navigate url ", type="String")
	public void setNavigateurl(String navigateurl) {
		this.navigateurl = navigateurl;
	}

	@StrutsTagAttribute(description="if allow target in blank.options:true,false ", type = "Boolean", defaultValue = "false")
	public void setAllowtargetinblank(String allowtargetinblank) {
		this.allowtargetinblank = allowtargetinblank;
	}

	public TabPage(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
		super(stack, request, response);
	}

	@Override
	public String getDefaultOpenTemplate() {
		return TEMPLATE;
	}

	@Override
	protected String getDefaultTemplate() {
		return TEMPLATE_CLOSE;
	}

	@Override
	protected void evaluateExtraParams() {
		// TODO Auto-generated method stub
		super.evaluateExtraParams();
		if(selected!=null)
			addParameter("selected", findValue(selected,Boolean.class));
		if(navigatetype !=null)
			addParameter("navigatetype", findString(navigatetype));
		if(navigateurl !=null)
			addParameter("navigateurl", findString(navigateurl));
		if(allowtargetinblank !=null)
			addParameter("allowtargetinblank", findValue(allowtargetinblank,Boolean.class));
	}
	 
}
